package com.itheima.ui;

import java.util.Arrays;

import static org.apache.commons.lang3.ArrayUtils.swap;

/**
 * @author zhangbaiyan
 * @date 2024-09-07 16:32
 * @description:
 * @version:
 */
public class quickSort {


    public static void main(String[] args) {

        int[] arr = {
                1, 3, 2, 5, 4,10,7,9,6
        };
       quickSort(arr,0,arr.length-1);

        System.out.println(Arrays.toString(arr));
    }

    public static void quickSort(int[] arr, int i, int j) {

        int start = i;
        int end = j;

        if (start >= end){
            return;
        }

        while (start != end){

            while (arr[end] >= arr[start] && start < end){
                end--;
            }
            while (arr[start] <= arr[end] && start < end){
                start++;
            }

            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;

        }

        if (start > i){
            quickSort(arr,i,start-1);
        }
        if (end < j){
            quickSort(arr,end+1,j);
        }
    }
}
